window.onload = function () {
  //@ts-ignore
  chrome.storage.sync.get(['isChecked'], (res: any) => {
    let isChecked: any = null;
    console.log(res);
    isChecked = res.isChecked
    if (isChecked === null) {
      //@ts-ignore
      chrome.storage.sync.set({ isChecked: '0' }, () => {
        console.log('set successed!');
        document.querySelector('#status')!.innerHTML = '否'
        return;
      });
    }
    if (isChecked == '1') {
      //@ts-ignore
      document.querySelector('#box')!.checked = true;
      document.querySelector('#status')!.innerHTML = '是'
    }
    else {
      //@ts-ignore
      document.querySelector('#box')!.checked = false;
      document.querySelector('#status')!.innerHTML = '否'
    }
  })
}
const isopen: any = () => {
  //@ts-ignore
  chrome.storage.sync.get(['isChecked'], (res) => {
    let isChecked: any = null;
    isChecked = res.isChecked
    console.log(isChecked);

    if (isChecked == '0') {
      //@ts-ignore
      chrome.storage.local.remove('isChecked', function () {
        console.log('remove 0');
        //@ts-ignore
        chrome.storage.sync.set({ isChecked: '1' }, () => {
          console.log('set 1');
          document.querySelector('#status')!.innerHTML = '是'
        });
      });
    }
    else {
      //@ts-ignore
      chrome.storage.local.remove('isChecked', function () {
        console.log('remove 1');
        //@ts-ignore
        chrome.storage.sync.set({ isChecked: '0' }, () => {
          console.log('set 0');
          document.querySelector('#status')!.innerHTML = '否'
        });
      });
    }
  });
  // alert(window.localStorage.getItem('isChecked'))
}
document.querySelector('#box')?.addEventListener('click', isopen);
